/**
 * 
 */
package org.singularity.io.util;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.UnsupportedEncodingException;

import org.singularity.io.CloseablePipe;

/**
 * @author vjache
 *
 */
public class PrintPipe<T> implements CloseablePipe<T> {
	
	private final PrintStream _ps;

	/**
	 * 
	 */
	public PrintPipe() {
		this(System.out);
	}
	
	public PrintPipe(PrintStream aPs) {
		_ps = aPs;
	}
	public PrintPipe(OutputStream aPs) throws UnsupportedEncodingException {
		this(new PrintStream(aPs,false,"UTF8"));
	}

	/* (non-Javadoc)
	 * @see java.io.Closeable#close()
	 */
	@Override
	public void close() throws IOException {
		_ps.close();
	}

	/* (non-Javadoc)
	 * @see org.singularity.io.Pipe#flush()
	 */
	@Override
	public void flush() throws IOException {
		_ps.flush();
	}

	/* (non-Javadoc)
	 * @see org.singularity.io.Pipe#push(java.lang.Object)
	 */
	@Override
	public void push(T aItem) throws IOException {
		_ps.println(aItem);
	}

}
